#if !defined(AFX_SOCKETUTILS_H__7B34CF88_2EC5_4519_8FED_907876817D4E__INCLUDED_)
#define AFX_SOCKETUTILS_H__7B34CF88_2EC5_4519_8FED_907876817D4E__INCLUDED_

// The following ifdef block is the standard way of creating macros which make exporting 
// from a DLL simpler. All files within this DLL are compiled with the TASKBARICON_EXPORTS
// symbol defined on the command line. this symbol should not be defined on any project
// that uses this DLL. This way any other project whose source files include this file see 
// TASKBARICON_API functions as being imported from a DLL, wheras this DLL sees symbols
// defined with this macro as being exported.
#ifdef SOCKETUTILS_EXPORTS
#define SOCKETUTILS_API __declspec(dllexport)
#else
#define SOCKETUTILS_API __declspec(dllimport)
#endif

// --------------------------------------------------------------------------
// The following interface is provided to manage a reference counter.
// This interface is similar to COM interface IUnknown, 
// except for method QueryInterface.
// --------------------------------------------------------------------------
class SOCKETUTILS_API ISimpleUnknown
{   
public:
	// The following method increments the reference counter.
	virtual ULONG AddRef()=0;

	// The following method decreases the reference counter.
	// If the reference count is equal to 0, it deletes 
	// the instance of ITaskBarIcon.		
	virtual ULONG Release()=0;

	// The following method returns the reference counter current value.
	virtual ULONG GetRef()=0;			
};

// --------------------------------------------------------------------------
// The function pointer type LP_RECVDATA_HANDLER_FUNC is used 
// to set up a callback (listener) for receive data.
// --------------------------------------------------------------------------
typedef void (__stdcall *LP_RECVDATA_HANDLER_FUNC)(const LPBYTE, DWORD);

// --------------------------------------------------------------------------
// The function pointer type LP_RECVEVT_HANDLER_FUNC is used 
// to set up a callback (listener) for receive events.
// --------------------------------------------------------------------------
typedef void (__stdcall *LP_RECVEVT_HANDLER_FUNC)(UINT);


// --------------------------------------------------------------------------
// The following interface is the "main" interface. 
// It keeps the code for showing an icon on the taskbar and for managing 
// events.
// --------------------------------------------------------------------------
class SOCKETUTILS_API ISocketUtils : virtual public ISimpleUnknown
{
public:
	// The following method creates an instance of ISocketUtils.
	// The reference counter is automatically set to 1.
	static ISocketUtils* Create();

	// The following method starts a server for listen 
	// and receive message.
	virtual bool Start(LPCTSTR strServerPort, UINT nSockType)=0;

	// The following method stops all servers.
	virtual void Stop()=0;

	// The following methods is used for message handlers.
	// They allows application to receive messages.
	// (e.g.broadcast, message) on the port).
	virtual void SetRecvDataHandler(LP_RECVDATA_HANDLER_FUNC p_Handler)=0; 

	// The following methods is used for message handlers.
	// They allows application to receive messages.
	// (e.g.broadcast, message) on the port).
	virtual void SetRecvEvtHandler(LP_RECVEVT_HANDLER_FUNC p_Handler)=0;

	// The following method send out a broadcast to all
	// You can add more params here
	virtual void Broadcast(ULONG command, LPCTSTR strUserData=NULL)=0;

	// The following method connect to server
	// and then you can send message to server
	virtual bool ConnectServer(LPCTSTR strIPAddr, LPCTSTR strPort, UINT nSockType)=0;

	// The following method disconnect from server
	// and then you breakup the link
	virtual void DisconnectServer()=0;

	// The following method send message to server
	// You can add more params here
	virtual void SendMsg(ULONG command, LPCTSTR strKey, LPCTSTR strUserData=NULL, int nLocalWnd=0, int nRemoteWnd=0)=0;
};
#endif // AFX_SOCKETUTILS_H__7B34CF88_2EC5_4519_8FED_907876817D4E__INCLUDED_